﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@algo-plus.co.uk website <http://www.algo-plus.co.uk/>
using System.Collections.Generic;
using FinPlusCompCore;
using FinPlusAssembler;
using FinPlusInterfaces;

namespace FinPlusCompAlgo
{
    public class AlgPlusGlassBox : FinPlusComponent
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }
        [State(Test = true)]
        public override string TestString { get { return Adapter.ToString(); } }

        public override IPods Adapter { get { return _adapter; } }
        private readonly IPods _adapter;
        private readonly List<IFinPlusComp> _virtualTraders;

        //construct
        public AlgPlusGlassBox(List<IFinPlusComp>  virtualTraders)
        {
            _adapter = IOC.New<IPods>(); 
            _virtualTraders = virtualTraders;
            IsValid = true;
        }

        //common control interface
        public override void CmdExecute(IPod command)
        {
            try
            {
                CmdCapture(command);
            }
            catch (CmdExecuteException e)
            {
                IsValid = Level.Error.Log(Id, Config, e.Message, e);
            }
        }

           
        public override void Dispose()
        {
            foreach(var virtualtrader in _virtualTraders)
                if (virtualtrader != null)
                 virtualtrader.Dispose();
        }

        //private
        private void AddVirtualTraders(IFinPlusComp conn)
        {
            
        }
    }
}
